const DeepCopy = require('../utils/deepCopy');

class AppCode {
  constructor() {
    let _this = this;
    this.project = {};
    /**
     * staticServer 公共静态文件管理系统 publicStaticServer
     */
    this.project.publicStaticServer_private = {
      JavaURL: {
        protocol: 'http',
        origin: '192.168.5.244',
        port: 8071,
        projectName: 'safeGate',
        version: 'v1',
      },
      LocalURL: {
        origin: '192.168.5.244',
        port: 8870,
      },
    };
    this.project.publicStaticServer_public = {
      session: {name: 'publicStaticServer'},                         // session 设置
      PublicURL: {
        origin: '192.168.5.244',
        port: 8870,
      },
      Project: {
        name: 'publicStaticServer',
        id: 92,
        appCode: 'publicStaticServer',
        userInfo: 'userInfo/getUseInfo',
        userOut: 'user/loginOut',
      }
    };

    this.publicConfig_private = {
      session: {
        secret: 's8^%4$V4KH5fd2dd0g',
      },
      cors: {
        methods: ['GET', 'PUT', 'POST', 'DELETE'],
        credentials: true,
        origin: ['^http:\/\/192\.168.*', 'null', '^http:\/\/222\.175\.119\.170.*', '^http:\/\/103\.239\.152\.13.*'],
      },                            // 跨域设置
    };
    this.publicConfig_public = {
      session: {
        name: 'session',
        // cookie: {maxAge: 1000 * 60 * 60 * 24}, // 1小时 //1k (s) * 60(min) *60 (hover) *24(day)
        cookie: {maxAge: 1000 * 60 * 60 * 6}, // 1小时 //1k (s) * 60(min) *60 (hover) *24(day)
        resave: false,
        saveUninitialized: false,
      },                         // session 设置
      CONSOLE: {
        use: true,
        level: 0,
      },                           // log 日志控制
      RequestDelayTime: 0,                     // 模拟网络延迟时间
      DelayLoadingCloseTime: 0.2,             // 延迟请求等待关闭时间
      VERSION: false,                          // 是否启用 API的版本号地址
      PublicImageServer: {
        upload: 'file/upload',
        userPhoto: 'image/userPhoto',
        src: `http://${_this.project.publicStaticServer_public.PublicURL.origin}:${_this.project.publicStaticServer_public.PublicURL.port}`,
      },                                           // 公用图片服务器
      LocalURL: {
        protocol: 'http',
        projectName: 'api',
        version: 'v1',
        logout: 'logout',
      }       // nodeJS 服务器配置
    };

    /**
     * safety
     */
    this.project.safeGate_private = {
      JavaURL: {
        protocol: 'http',
        origin: '192.168.5.9',
        port: 8071,
        projectName: 'safeGate',
        version: 'v1',
      },
      LocalURL: {
        origin: '192.168.5.244',
        port: 8867,
      },
    };
    this.project.safeGate_public = {
      session: {name: 'safeGate'},                         // session 设置
      Project: {
        name: 'safety',
        id: 2,
        appCode: 'safeGate',
        userInfo: 'userInfo/getUseInfo',
        userOut: 'user/loginOut',
      }
    };
    /**
     * SSO
     */
    this.project.sso_private = {
      JavaURL: {
        protocol: 'http',
        origin: '192.168.5.9',
        port: 8071,
        projectName: 'safeGate',
        version: 'v1',
      },
      /**
       * 192.168.5.26 刘花
       * 192.168.5.31 刘静
       * 192.168.5.29 李毅
       * 192.168.5.109 朱左鹏
       * 192.168.5.27 孙月红
       * 192.168.5.28 李娜
       * 192.168.5.21 姚均师
       */
      user: [
        {
          userName: '刘花',
          host: '192.168.5.26',
        },
        {
          userName: '刘静',
          host: '192.168.5.31',
        },
        {
          userName: '李毅',
          host: '192.168.5.29',
        },
        {
          userName: '朱左鹏',
          host: '192.168.5.109',
        },
        {
          userName: '孙月红',
          host: '192.168.5.27',
        },
        {
          userName: '牛冀伟',
          host: '192.168.5.20',
        },
        {
          userName: '方新国',
          host: '192.168.5.19',
        },
        {
          userName: '李娜',
          host: '192.168.5.28',
        },
        {
          userName: '姚均师',
          host: '192.168.5.21',
        },
        {
          userName: '系统',
          host: '192.168.5.244',
        },
      ],
      LocalURL: {
        origin: '192.168.5.244',
        port: 8866,
      },
    };
    this.project.sso_public = {
      session: {name: 'sso'},                         // session 设置
      URL: {
        login: {
          method: 'post',
          path: 'sso/login'
        },
        logout: {
          method: 'post',
          path: 'sso/logOut'
        },
        checkTicket: {
          method: 'get',
          path: 'sso/checkTicket'
        }
      },
      Project: {
        name: 'SSO',
        id: 0,
        appCode: 'SSO',
      }
    };
    /**
     * zxwms
     */
    this.project.zxwms_private = {
      JavaURL: {
        protocol: 'http',
        origin: '192.168.5.244',
        port: 8080,
        projectName: 'zxwms',
        version: 'v1',
      },
      LocalURL: {
        origin: '192.168.5.244',
        port: 6688,
      },
    };
    this.project.zxwms_public = {
      session: {name: 'zxwms'},                         // session 设置
      Project: {
        name: 'FEzxwms',
        id: 92,
        appCode: 'zxwms',
        userInfo: 'userInfo',
        userOut: 'userInfo/logout',
        socket: 6689
      }
    };
    /**
     * devJava
     */
    this.project.devJava_private = {};
    this.project.devJava_public = {
      LocalURL: {
        origin: '192.168.5.244',
        port: 5556,
      },
      Project: {
        name: 'devJava',
        appCode: 'devJava'
      },
    };
    /**
     * bx 报销系统 reimbursement
     */
    this.project.reimbursement_private = {
      JavaURL: {
        protocol: 'http',
        // origin: '192.168.5.244',
        // origin: '192.168.5.37',
        port: 8686,
        // port: 7676,
        origin: '192.168.5.19',
        // port: 8081,
        projectName: 'reimbursement',
        version: 'v1',
      }
    };
    this.project.reimbursement_public = {
      VERSION: true,                          // 是否启用 API的版本号地址
      session: {name: 'reimbursement'},   // session 设置
      LocalURL: {
        origin: '192.168.5.244',
        port: 8873,
      },
      Project: {
        name: 'FEreimbursement',
        id: 92,
        appCode: 'reimbursement',
        userInfo: 'userInfo',
        userOut: 'logout'
      }
    };
    /**
     * bx 数据交互平台 data-exchange
     */
    this.project.dataGate_private = {
      JavaURL: {
        protocol: 'http',
        origin: '192.168.5.9',
        port: 7081,
        projectName: 'dataGate',
      }
    };
    this.project.dataGate_public = {
      session: {name: 'dataGate'},   // session 设置
      LocalURL: {
        origin: '192.168.5.244',
        port: 8872,
      },
      Project: {
        name: 'FEdataExchange',
        id: 1029,
        appCode: 'dataGate',
        userInfo: 'userInfo',
        userOut: 'logout'
      }
    };
  }

  get Projects() {
    let projects = {};
    for (let index in this.project) {
      if (!this.project.hasOwnProperty(index)) continue;
      if (/_public$/.test(index)) {
        let name = index.split('_public')[0];
        projects[name] = DeepCopy(this.project[name + '_public'], this.project[name + '_private']);
      }
    }
    return projects;
  }

  get ProjectsPublic() {
    let projects = {};
    for (let index in this.project) {
      if (!this.project.hasOwnProperty(index)) continue;
      if (/_public$/.test(index)) {
        projects[index.split('_public')[0]] = this.project[index]
      }
    }
    return projects;
  }

  get(appCode, Private) {
    return Private ?
      DeepCopy(this.publicConfig_public, this.publicConfig_private, this.project[appCode + '_public'], this.project[appCode + '_private'], {Projects: this.Projects}) :
      DeepCopy(this.publicConfig_public, this.project[appCode + '_public'], {Projects: this.ProjectsPublic});
  }
}

module.exports = AppCode;